package com.ihome.android.util.exception;

import android.content.Context;
import android.widget.Toast;

/**
 * @author Emerson
 */
public class ITVException extends Exception {
	private static final long	serialVersionUID	= 1L;
	private int					statusCode			= -1;

	public ITVException() {
		super();
	}

	public ITVException(Context context, int statusCode) {
		super(getMsg(context, statusCode));
		this.statusCode = statusCode;
		switch (statusCode) {
		default:
			return;
		case ITVException.DOWNLOAD_IS_DOWNLOADING:
			Toast.makeText(context, "视频正在下载中，不用重复下载!", Toast.LENGTH_SHORT).show();
			break;
		case ITVException.DOWNLOAD_HAVA_DOWNLOADED:
			Toast.makeText(context, "视频已下载，不用重复下载!", Toast.LENGTH_SHORT).show();
			break;
		case ITVException.DOWNLOAD_NO_FILE_PATH:
			Toast.makeText(context, "文件路径为空!", Toast.LENGTH_SHORT).show();
			break;
		}
	}

	public ITVException(int statusCode) {
		super(getMsg(null, statusCode));
		this.statusCode = statusCode;
	}

	public ITVException(String msg) {
		super(msg);
	}

	public ITVException(Exception cause) {
		super(cause);
	}

	public ITVException(Throwable throwable) {
		super(throwable);
	}

	public ITVException(String msg, int statusCode) {
		super(msg);
		this.statusCode = statusCode;
	}

	public ITVException(Exception cause, int statusCode) {
		super(cause);
		this.statusCode = statusCode;
	}

	public ITVException(String msg, Exception cause) {
		super(msg, cause);
	}

	public ITVException(String msg, Exception cause, int statusCode) {
		super(msg, cause);
		this.statusCode = statusCode;
	}

	public ITVException(String detailMessage, Throwable throwable) {
		super(detailMessage, throwable);
	}

	public int getStatusCode() {
		return this.statusCode;
	}

	public void setStatusCode(int statusCode) {
		this.statusCode = statusCode;
	}

	public static String getMsg(Context context, int code) {
		// if (599 > code) {
		// return null == context ? "数据请求失败！" :
		// context.getString(R.string.exception_data_request_fail);
		// }
		// else if (899 < code && code < 920) {
		// return null == context ? "数据解析错误！" :
		// context.getString(R.string.exception_json_ananlytic_fail);
		// }
		// else

		if (-88036 < code && code < 88020) {
			if (code == HTTP_READ_IO_EXCEPTION || code == HTTP_POST_IO_EXCEPTION || code == HTTP_GET_IO_EXCEPTION) {
				return "尊敬的用户您好，客户端网络连接超时，请稍候重试！";
			}
			return "尊敬的用户您好，客户端网络连接超时，请稍候重试！";
		}
		
		return "";
	}

	@Override
	public String toString() {
		return super.getMessage() + " ( " + statusCode + " )";
	}

	// ------------- [900 , 919]
	public static final int	AUTH_ID											= 136;
	// --------------------------------------------------------------
	/** JsonAnalytic解析json时，解析字符串为空 */
	public static final int	JSON_ANALYTIC_STRING_NULL						= -88901;
	/** OTT 参数不对 */
	public static final int	OTT_ENCRYPT_PARAMS_ERROR						= -88100;

	// -------------- [920 , 939]------------------------
	public static final int	HTTP_CONNECTION_NO								= -88019;
	public static final int	HTTP_READ_IO_EXCEPTION							= -88020;
	public static final int	HTTP_GET_HTTPS_URL_CONN_MALFORMED_URL_EXCEPTION	= -88021;
	public static final int	HTTP_GET_HTTPS_URL_CONN_IO_EXCEPTION			= -88022;
	public static final int	HTTP_GET_HTTPS_URL_CONN_NO_SUCH_ALG_EXCEPTION	= -88023;
	public static final int	HTTP_GET_HTTPS_URL_CONN_KEYMANAGEMENT_EXCEPTION	= -88024;
	public static final int	HTTP_GET_HTTP_URL_CONN_MALFORMED_URL_EXCEPTION	= -88025;
	public static final int	HTTP_GET_HTTP_URL_CONN_IO_EXCEPTION				= -88026;
	public static final int	HTTP_READ_HTTP_RESPONSE_IO_EXCEPTION			= -88027;
	public static final int	HTTP_POST_UNSUPPORTED_ENCODING_EXCEPTION		= -88030;
	public static final int	HTTP_POST_CLIENT_PROTOCOL_EXCEPTION				= -88031;
	public static final int	HTTP_POST_IO_EXCEPTION							= -88032;
	public static final int	HTTP_GET_CLIENT_PROTOCOL_EXCEPTION				= -88033;
	public static final int	HTTP_GET_IO_EXCEPTION							= -88034;
	public static final int	HTTP_GETINPUTSTRING_CLIENT_PROTOCOL_EXCEPTION	= -88035;
	public static final int	HTTP_GETINPUTSTRING_IO_EXCEPTION				= -88036;
	// ---------------[940 , 959]-------------------------
	public static final int	ENCRYPT_NO_SUCH_PADDING_EXCEPTION				= -88040;
	public static final int	ENCRYPT_NO_SUCH_ALGORITHM_EXCEPTION				= -88041;
	public static final int	ENCRYPT_INVALID_KEY_EXCEPTION					= -88042;
	public static final int	ENCRYPT_ILLEGAL_BLOCKSIZE_EXCEPTION				= -88043;
	public static final int	ENCRYPT_BAD_PADDING_EXCEPTION					= -88044;

	public static final int	DECRYPT_NO_SUCH_PADDING_EXCEPTION				= -88045;
	public static final int	DECRYPT_NO_SUCH_ALGORITHM_EXCEPTION				= -88046;
	public static final int	DECRYPT_INVALID_KEY_EXCEPTION					= -88047;
	public static final int	DECRYPT_ILLEGAL_BLOCKSIZE_EXCEPTION				= -88048;
	public static final int	DECRYPT_BAD_PADDING_EXCEPTION					= -88049;

	public static final int	GETRAWKEY_NO_SUCH_ALGORITHM_EXCEPTION			= -88050;

	// ---------------[960 , 969]-------------------------
	public static final int	DOWNLOAD_NO_STORAGE_SPACE						= -88060;
	public static final int	DOWNLOAD_CONTENT_LENGTH_ZERO					= -88061;
	public static final int	DOWNLOAD_FILE_NOT_FOUND_EXCEPTION				= -88062;
	public static final int	DOWNLOAD_DOINBACKGROUND_IO_EXCEPTION			= -88063;
	public static final int	DOWNLOAD_WRITE_IO_EXCEPTION						= -88064;
	public static final int	DOWNLOAD_NO_FILE_PATH							= -88065;
	public static final int	DOWNLOAD_HAVA_DOWNLOADED						= -88066;
	public static final int	DOWNLOAD_IS_DOWNLOADING							= -88067;
	public static final int	UTIL_ENCODERBYMD5_EXCEPTION						= -88080;

	// 应用[xxx]没有产品包且当前用户[xxx]未订购过
	public static final int	APP_ORDER_AUTH_FAILURE							= -88003;
	// 应用商城用户名已被注册错误
	public static final int	APP_USERNAME_IS_UNAVAILABLE						= 13000;
	
	public static final int	HTTP_GET_HTTP_URL_UnsupportedEncodingException	= 1010;
	
	
	
	
	public static final int	CODE_APP_CATEGORY_ONE							= -88108;//没有展示分类配置记录
	public static final int	CODE_APP_CATEGORY_TWO							= -88109;//推荐展示标志位值[{0}]不合法
	public static final int	CODE_APP_CATEGORY_THREE							= -88110;//父分类ID[{0}]不合法
	public static final int	CODE_CATEGORY_APP_ONE							= -88111;//二级分类[xxx]不存在 
	public static final int	CODE_CATEGORY_APP_TWO							= -88112;//推荐的分类[xxx]是一级分类
	public static final int	FILE_UPLOAD_ERROR								= -88420;//文件上传失败
	public static final int	FILE_SIZE_ERROR									= -88421;//文件过大
	public static final int	WELCOMECONFIG_NO_MATCH							= -88507;//匹配不到欢迎页信息
	public static final int	CONTENT_NO_MATCH								= -88509;//找不到内容信息
	public static final int	SUCCESS											= 0;
	
	public static final int	CODE_LOGIN_ONE									= -88406;//UserToken不能为空
	public static final int	CODE_SESSIONKEY									= -88403;//Sessionkey为空,-88403
	public static final int	CODE_LOGINOUT_ONE								= -88004;//Sessionkey非法或者已经过期 -88004
	public static final int	CODE_LOGINOUT_THREE								= -88005;//用户[xxx]未登录或者已经超时
	
	
	
}

